<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <!--    <script src="/static/js/framework-ui.js"></script>-->
    <!--    <script src="/static/js/framework-clientdata.js"></script>-->

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--    配置select多选相关-->
    <!--    <script src="/static/layui/dist/xm-select.js"></script>-->


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}

    <script src="/static/build/tracking-min.js"></script>
    <script src="/static/build/data/face-min.js"></script>
    <script src="/static/build/data/eye-min.js"></script>
    <script src="/static/build/data/mouth-min.js"></script>
</head>
<body>
<style>
    html, body {
        background-color: #FFF !important;
    }
    .modal-body {
        background-color: #fff;
        padding: 15px
    }
    .page-header {
        margin-top: 15px !important;
    }
    .geographic input {
        width: 100px !important;
        float: left;
        margin-right: 15px;
    }
    .new-content {
        padding: 15px 0px
    }
    .config_img {
        width: 45px;
        height: 45px;
        margin-top: 15px;
    }
</style>
<div class="modal-body">
    <div class="modal-header">
        <div class="assistant_header">
            <button type="button" class="close" data-dismiss="modal" close="true">
                <span aria-hidden="true">×</span>
            </button>
            <h4 class="modal-title">
                <span class="fa fa-legal"></span>回复信息
            </h4>
        </div>
    </div>
    <div class="new-content">
        <form class="form-horizontal layui-form">

            <div class="form-group">
                <label class="col-sm-1 control-label">*所属景区:</label>
                <div class="col-sm-3">
                    <select name="colony_id" lay-verify="colony_id" lay-filter="colony_id" class="select"  lay-search="">
                    <option value="" >请选择</option>
                    <option {if condition="$detail['colony_id'] eq 0"} selected {/if} value="0" >平台</option>
                    {volist name="community" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['colony_id'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                    </select>
                </div>
            </div>

            <div  class="form-group" >
                <label class="col-sm-1 control-label">标题:</label>
                <div class="col-sm-8">
                    <textarea name="title" class="layui-textarea">{$detail.title}</textarea>
                </div>
            </div>

            <!--图文模型&单页模型-->
            <div class="form-group"  >
                <label class="col-sm-1 control-label">回复:</label>
                <div class="col-sm-8">
                    <textarea id="content" >{$detail.content}</textarea>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">关联标签:</label>
                <div class="col-sm-6 tag" style="margin-top:10px">
                    {volist name="tag" id="vo"}
                        <input type="checkbox" name="tag[]" lay-skin="primary" value="{$vo.name}" title="{$vo.name}" {if condition="$vo['check'] eq 1"} checked {/if} >
                    {/volist}
                </div>
            </div>

            <input type="hidden" name="id" value="{$detail.id}">
        </form>
    </div>
    <div class="assistant_button add_button">
        <a type="button" class="layui-btn layui-btn-primary js_quit" href="{:URL('community/answer/index')}" >取消</a>
<!--                <button type="button" class="btn btn-primary btn-sm js_add" _event="add" data-id="0" data-name="">保存</button>-->
        {if condition="$detail['status'] eq 3"}
        <a type="button" class="layui-btn js_add newsave" >保存</a>
        <a type="button" class="layui-btn layui-btn-danger js_add release" >发布</a>
        {/if}
    </div>

</div>


<script>
    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form', 'jquery', 'layer', 'laydate','tinymce'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var tinymce = layui.tinymce;
        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {

        });


        //触发四级联动
        form.on('select(colony_id)', function (data) {
            var id = data.value;

            $.ajax({
                type: 'post',
                url: "{:URL('common/Common/getTag')}",
                data: {id: id},
                dataType: 'JSON',
                success: function (res) {
                    var list = res.data;
                    var html1 = '';
                    $.each(list, function (e, v) {
                        if(v.check==1){
                            html1 += '<input type="checkbox" name="tag[]" lay-skin="primary" value="'+v.name+'" title="'+v.name+'" disabled="" >';
                        }else{
                            html1 += '<input type="checkbox" name="tag[]" lay-skin="primary" value="'+v.name+'" title="'+v.name+'" >';
                        }

                    });
                    $(".tag").html(html1);
                    form.render();
                },
                error: function (res) {
                }
            });
        });

        $(".newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            data.push({name: "status", value: 3});
            $.ajax({
                type: 'post',
                url: "{:URL('community/answer/doAnswer')}",
                data: data,
                dataType: 'JSON',
                success: function (res) {
                    if (res.code != 0) {
                        layer.alert(res.msg);
                    } else {
                        window.location.href = "{:URL('community/answer/index')}";
                    }
                },
                error: function (res) {

                }
            });
        })

        $(".release").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            data.push({name: "status", value: 1});


            layer.confirm('发布后该信息不能进行修改操作，是否发布?',{
                cancel: function(index, layero){

                }
            }, function(index) {
                $.ajax({
                    type: 'post',
                    url: "{:URL('community/answer/doAnswer')}",
                    data: data,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code != 0) {
                            layer.alert(res.msg);
                        } else {
                            window.location.href = "{:URL('community/answer/index')}";
                        }
                    },
                    error: function (res) {

                    }
                });
                return false
            }, function(index, layero){

            })


        })
        form.render('select');

    });

</script>

</body>
</html>